<?php
/**
 * @version		$Id: mod_login.php 20806 2011-02-21 19:44:59Z dextercowley $
 * @package		Joomla.Site
 * @subpackage	mod_login
 * @copyright	Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

// Include the syndicate functions only once
require_once dirname(__FILE__).'/helper.php';

$layoutmodule = $params->get('layoutlogin', 'default');
$news_catid = $params->get('news_catid');
$event_catid = $params->get('event_catid');
$promotion_catid = $params->get('promotion_catid');

if($layoutmodule == 'default'){
	$items = modWrdmetroHelper::getItemsCategory($params->get('event_catid'), $params->get('news_catid'),$params->get('promotion_catid'));
	foreach ($items as $val=>$row){
		$items[$val]->gallery = modWrdmetroHelper::getItemsImage($row->id);
		
		foreach ($items[$val]->gallery as $kval => $krow){
			$items[$val]->gallery[$krow->description] = $krow->url;
			unset($items[$val]->gallery[$kval]);
		}
		
		
	
		if($row->catid == $params->get('event_catid'))
			$items[$val]->ktype = 'event';
		elseif($row->catid == $params->get('news_catid'))
			$items[$val]->ktype = 'news';
		elseif($row->catid == $params->get('promotion_catid'))
			$items[$val]->ktype = 'promotion';
	}
	
	
	if(count($items) < 14){
		for ($i = count($items); $i <= 14; $i++){
			$items[$i] = $items[array_rand($items)];
		}
	}
}
elseif($layoutmodule == 'promotion'){
	$items = modWrdmetroHelper::getItemsCategory(0,0,$params->get('promotion_catid'));
	foreach ($items as $val=>$row){
		$items[$val]->gallery = modWrdmetroHelper::getItemsImage($row->id);
	
		foreach ($items[$val]->gallery as $kval => $krow){
			$items[$val]->gallery[$krow->description] = $krow->url;
			unset($items[$val]->gallery[$kval]);
		}
	
		if($row->catid == $params->get('event_catid'))
			$items[$val]->ktype = 'event';
		elseif($row->catid == $params->get('news_catid'))
		$items[$val]->ktype = 'news';
		elseif($row->catid == $params->get('promotion_catid'))
		$items[$val]->ktype = 'promotion';
	}
	
	if(count($items) < 11){
		for ($i = count($items); $i <= 14; $i++){
			$items[$i] = $items[array_rand($items)];
		}
	}
	
	//print_r($items);
}
elseif($layoutmodule == 'news'){
	$items = modWrdmetroHelper::getItemsCategory(0,0,$params->get('news_catid'));
	foreach ($items as $val=>$row){
		$items[$val]->gallery = modWrdmetroHelper::getItemsImage($row->id);

		foreach ($items[$val]->gallery as $kval => $krow){
			$items[$val]->gallery[$krow->description] = $krow->url;
			unset($items[$val]->gallery[$kval]);
		}

		if($row->catid == $params->get('event_catid'))
			$items[$val]->ktype = 'event';
		elseif($row->catid == $params->get('news_catid'))
		$items[$val]->ktype = 'news';
		elseif($row->catid == $params->get('promotion_catid'))
		$items[$val]->ktype = 'promotion';
	}

	if(count($items) < 11){
		for ($i = count($items); $i <= 14; $i++){
			$items[$i] = $items[array_rand($items)];
		}
	}
}
elseif($layoutmodule == 'event'){
	$items = modWrdmetroHelper::getItemsCategory(0,0,$params->get('event_catid'));
	foreach ($items as $val=>$row){
		$items[$val]->gallery = modWrdmetroHelper::getItemsImage($row->id);

		foreach ($items[$val]->gallery as $kval => $krow){
			$items[$val]->gallery[$krow->description] = $krow->url;
			unset($items[$val]->gallery[$kval]);
		}

		if($row->catid == $params->get('event_catid'))
			$items[$val]->ktype = 'event';
		elseif($row->catid == $params->get('news_catid'))
		$items[$val]->ktype = 'news';
		elseif($row->catid == $params->get('promotion_catid'))
		$items[$val]->ktype = 'promotion';
	}

	if(count($items) < 11){
		for ($i = count($items); $i <= 14; $i++){
			$items[$i] = $items[array_rand($items)];
		}
	}
}
else{
	$item = modWrdmetroHelper::getItemProduct();
	$item->gallery = modWrdmetroHelper::getProductImage($item->id);
}

require JModuleHelper::getLayoutPath('mod_wrdmetro', $layoutmodule);